/**
 * 
 * author：gaoxingliang@outlook.com
 * created:2015年8月16日 下午12:12:02  
 */
package org.gxl.learn;

import java.io.File;
import java.io.FileInputStream;


import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * 使用POI读取excel文件  xlsx 2007及以后的文件
 * @author gxl
 *
 */
public class ReadExcelByPOIUseXSSF
{

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception
	{
		File f = new File("poi.xlsx");
		XSSFWorkbook w = new XSSFWorkbook(new FileInputStream (f));
		Sheet s = w.getSheetAt(0);
		int firstRow = 0;
		int lastRow = s.getLastRowNum();
		for (int i = 0; i< lastRow ; i ++)
		{
			Row row = s.getRow(i);
			int cellC = row.getLastCellNum();
			for (int j =0 ; j< cellC; j ++)
			{
				Cell c = row.getCell(j);
				System.out.print(c.getStringCellValue() + " ");
			}
			System.out.println();
		}
		
		//stream should close
		
	}

}
